summaryrefslogtreecommitdiffstats
path: root/src/common/settings_common.h
blob: 81d59115d3f81b211a1a1a2c4519ab52d1da3b49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <forward_list>
#include <functional>
#include <map>
#include <string>
#include <typeindex>
#include "common/common_types.h"

namespace Settings {

enum class Category : u32 {
    Audio,
    Core,
    Cpu,
    CpuDebug,
    CpuUnsafe,
    Renderer,
    RendererAdvanced,
    RendererDebug,
    System,
    SystemAudio,
    DataStorage,
    Debugging,
    DebuggingGraphics,
    Miscellaneous,
    Network,
    WebService,
    AddOns,
    Controls,
    Ui,
    UiGeneral,
    UiLayout,
    UiGameList,
    Screenshots,
    Shortcuts,
    Multiplayer,
    Services,
    Paths,
    MaxEnum,
};

class BasicSetting;

class Linkage {
public:
    explicit Linkage(u32 initial_count = 0);
    ~Linkage();
    std::map<Category, std::forward_list<BasicSetting*>> by_category{};
    std::vector<std::function<void()>> restore_functions{};
    u32 count;
};

class BasicSetting {
protected:
    explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
                          bool save_, bool runtime_modifiable_);

public:
    virtual ~BasicSetting();

    /* Data retrieval */

    [[nodiscard]] virtual std::string ToString() const = 0;
    [[nodiscard]] virtual std::string ToStringGlobal() const;
    [[nodiscard]] virtual std::string DefaultToString() const = 0;
    [[nodiscard]] virtual std::string MinVal() const = 0;
    [[nodiscard]] virtual std::string MaxVal() const = 0;
    virtual void LoadString(const std::string& load) = 0;
    [[nodiscard]] virtual std::string Canonicalize() const = 0;

    /* Identification */

    [[nodiscard]] virtual std::type_index TypeId() const = 0;
    [[nodiscard]] virtual constexpr bool IsEnum() const = 0;
    /**
     * Returns whether the current setting is Switchable.
     *
     * @returns If the setting is a SwitchableSetting
     */
    [[nodiscard]] virtual constexpr bool Switchable() const {
        return false;
    }
    /**
     * Returns the save preference of the setting i.e. when saving or reading the setting from a
     * frontend, whether this setting should be skipped.
     *
     * @returns The save preference
     */
    [[nodiscard]] bool Save() const;
    [[nodiscard]] bool RuntimeModfiable() const;
    [[nodiscard]] constexpr u32 Id() const {
        return id;
    }
    /**
     * Returns the setting's category AKA INI group.
     *
     * @returns The setting's category
     */
    [[nodiscard]] Category Category() const;
    /**
     * Returns the label this setting was created with.
     *
     * @returns A reference to the label
     */
    [[nodiscard]] const std::string& GetLabel() const;

    /* Switchable settings */

    virtual void SetGlobal(bool global);
    [[nodiscard]] virtual bool UsingGlobal() const;

private:
    const std::string label;      ///< The setting's label
    const enum Category category; ///< The setting's category AKA INI group
    const u32 id;
    const bool save;
    const bool runtime_modifiable;
};

} // namespace Settings